#ifndef BONDERWORKHOLDERCONFIG_H
#define BONDERWORKHOLDERCONFIG_H

#include "BasicElement/scaxis.h"
#include "configManager/configobject.h"

class BonderWorkHolderConfig : public ConfigObject
{
    Q_OBJECT

    Q_PROPERTY(QString beltRunDirection READ beltRunDirection WRITE setBeltRunDirection NOTIFY beltRunDirectionChanged)
    Q_PROPERTY(int detectHasTrayMaxTime READ detectHasTrayMaxTime WRITE setDetectHasTrayMaxTime NOTIFY
                   detectHasTrayMaxTimeChanged)
    Q_PROPERTY(int getNewTrayTimeout READ getNewTrayTimeout WRITE setGetNewTrayTimeout NOTIFY getNewTrayTimeoutChanged)
    Q_PROPERTY(
        int pushoutTrayTimeout READ pushoutTrayTimeout WRITE setPushoutTrayTimeout NOTIFY pushoutTrayTimeoutChanged)

    Q_PROPERTY(double postBondOffsetCorrectionX READ postBondOffsetCorrectionX WRITE setPostBondOffsetCorrectionX NOTIFY
                   postBondOffsetCorrectionXChanged)
    Q_PROPERTY(double postBondOffsetCorrectionY READ postBondOffsetCorrectionY WRITE setPostBondOffsetCorrectionY NOTIFY
                   postBondOffsetCorrectionYChanged)
    Q_PROPERTY(double postBondLimitX READ postBondLimitX WRITE setPostBondLimitX NOTIFY postBondLimitXChanged)
    Q_PROPERTY(double postBondLimitY READ postBondLimitY WRITE setPostBondLimitY NOTIFY postBondLimitYChanged)

public:
    BonderWorkHolderConfig(QObject *parent = nullptr) : ConfigObject(parent)
    {
        setOptionalProperty("beltRunDirection", toVariantList(SCAxis::DirEnumInfo().names()));
        init();
    }

    QString beltRunDirection() const
    {
        return m_beltRunDirection;
    }

    int detectHasTrayMaxTime() const
    {
        return m_detectHasTrayMaxTime;
    }

    int getNewTrayTimeout() const
    {
        return m_getNewTrayTimeout;
    }

    int pushoutTrayTimeout() const
    {
        return m_pushoutTrayTimeout;
    }

    double postBondLimitX() const
    {
        return m_postBondLimitX;
    }

    double postBondLimitY() const
    {
        return m_postBondLimitY;
    }

    double postBondOffsetCorrectionX() const
    {
        return m_postBondOffsetCorrectionX;
    }

    double postBondOffsetCorrectionY() const
    {
        return m_postBondOffsetCorrectionY;
    }

public slots:
    void setBeltRunDirection(QString beltRunDirection)
    {
        if (m_beltRunDirection == beltRunDirection)
            return;

        m_beltRunDirection = beltRunDirection;
        emit beltRunDirectionChanged(m_beltRunDirection);
    }

    void setDetectHasTrayMaxTime(int detectHasTrayMaxTime)
    {
        if (m_detectHasTrayMaxTime == detectHasTrayMaxTime)
            return;

        m_detectHasTrayMaxTime = detectHasTrayMaxTime;
        emit detectHasTrayMaxTimeChanged(m_detectHasTrayMaxTime);
    }

    void setGetNewTrayTimeout(int getNewTrayTimeout)
    {
        if (m_getNewTrayTimeout == getNewTrayTimeout)
            return;

        m_getNewTrayTimeout = getNewTrayTimeout;
        emit getNewTrayTimeoutChanged(m_getNewTrayTimeout);
    }

    void setPushoutTrayTimeout(int pushoutTrayTimeout)
    {
        if (m_pushoutTrayTimeout == pushoutTrayTimeout)
            return;

        m_pushoutTrayTimeout = pushoutTrayTimeout;
        emit pushoutTrayTimeoutChanged(m_pushoutTrayTimeout);
    }

    void setPostBondLimitX(double postBondLimitX)
    {
        //        qWarning("Floating point comparison needs context sanity check");
        if (qFuzzyCompare(m_postBondLimitX, postBondLimitX))
            return;

        m_postBondLimitX = postBondLimitX;
        emit postBondLimitXChanged(m_postBondLimitX);
    }

    void setPostBondLimitY(double postBondLimitY)
    {
        //        qWarning("Floating point comparison needs context sanity check");
        if (qFuzzyCompare(m_postBondLimitY, postBondLimitY))
            return;

        m_postBondLimitY = postBondLimitY;
        emit postBondLimitYChanged(m_postBondLimitY);
    }

    void setPostBondOffsetCorrectionX(double postBondOffsetCorrectionX)
    {
//        qWarning("Floating point comparison needs context sanity check");
        if (qFuzzyCompare(m_postBondOffsetCorrectionX, postBondOffsetCorrectionX))
            return;

        m_postBondOffsetCorrectionX = postBondOffsetCorrectionX;
        emit postBondOffsetCorrectionXChanged(m_postBondOffsetCorrectionX);
    }

    void setPostBondOffsetCorrectionY(double postBondOffsetCorrectionY)
    {
//        qWarning("Floating point comparison needs context sanity check");
        if (qFuzzyCompare(m_postBondOffsetCorrectionY, postBondOffsetCorrectionY))
            return;

        m_postBondOffsetCorrectionY = postBondOffsetCorrectionY;
        emit postBondOffsetCorrectionYChanged(m_postBondOffsetCorrectionY);
    }

signals:
    void beltRunDirectionChanged(QString beltRunDirection);

    void detectHasTrayMaxTimeChanged(int detectHasTrayMaxTime);

    void getNewTrayTimeoutChanged(int getNewTrayTimeout);

    void pushoutTrayTimeoutChanged(int pushoutTrayTimeout);

    void postBondLimitXChanged(double postBondLimitX);

    void postBondLimitYChanged(double postBondLimitY);

    void postBondOffsetCorrectionXChanged(double postBondOffsetCorrectionX);

    void postBondOffsetCorrectionYChanged(double postBondOffsetCorrectionY);

private:
    QString m_beltRunDirection;
    int m_detectHasTrayMaxTime = 1000;
    int m_getNewTrayTimeout = 50000;
    int m_pushoutTrayTimeout = 30000;
    double m_postBondLimitX = 0.02;
    double m_postBondLimitY = 0.02;
    double m_postBondOffsetCorrectionX = 0;
    double m_postBondOffsetCorrectionY = 0;
};

#endif    // BONDERWORKHOLDERCONFIG_H
